#include"Date.h"


Date::Date(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}

Date::Date(Date& y)
{
	_year = y._year;
	_month = y._month;
	_day = y._day;
}

int Date::getyear()
{
	return _year;
}

int Date::getmonth()
{
	return _month;
}

int Date::getday()
{
	return _day;
}

int getmonthday(int year, int month)
{
	int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
	{
		return 29;
	}
	return a[month];
}

void Date::operator+=(int y)
{
	_day += y;
	while (_day > getmonthday(_year, _month))
	{
		_day -= getmonthday(_year, _month);
		_month++;
		if (_month > 12)
		{
			_year++;
			_month = 1;
		}
	}
}

Date Date::operator+(int y)
{
	Date temp(*this);
	temp += y;
	return temp;
}

Date& Date::operator=(Date y)
{
	_year = y._year;
	_month = y._month;
	_day = y._day;
	return *this;
}



void Date::Print()
{
	cout << _year << "-" << _month << "-" << _day << endl;
}

void Date::operator-=(int y)
{
	_day -= y;
	while (_day <=0)
	{
		_month--;
		if (_month == 0)
		{
			_month = 12;
			_year--;
		}
		_day += getmonthday(_year, _month);
	}
}

bool Date::operator<(Date y)
{
	return _year < y._year && _month < y._month && _day < y._day;
}

bool Date::operator==(Date y)
{
	return _year == y._year && _month == y._month && _day == y._day;
}

bool Date::operator>=(Date y)
{
	return !(*this < y);
}

bool Date::operator<=(Date y)
{
	return !(*this > y);
}

bool Date::operator>(Date y)
{
	return !(*this < y && *this == y);
}

bool Date::operator>(Date y)
{
	return !(*this < y && *this == y);
}

void Date::operator++()
{
	*this += 1;
}

Date Date::operator++(int)
{
	Date temp(*this);
	temp += 1;
	return temp;
}

void Date::operator--()
{
	*this -= 1;
}

Date Date::operator--(int)
{
	Date temp(*this);
	temp -= 1;
	return temp;
}